<?php

namespace app\api\controller;

use app\admin\model\Login as ModelLogin;
use app\common\controller\Api;
use think\Db;

/**
 * 会员验证接口
 */
class Member extends Api
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function index()
    {
        // 获取 token
        $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
        if (empty($token)) {
            $this->error(" Token 不能为空");
        }
        $mtoken = Db::name('login_token')->where('token', $token)->find();
        if (empty($mtoken)) {
            $this->error("您未登录，请重新登陆！");
        }
        $member = ModelLogin::where(['id' => $mtoken['member_id']])->find();
        if (empty($member)) {
            $this->error("会员不存在或已被冻结！");
        }
        
        $this->success("成功获取数据", $member);
    }
}